package yunjiao.javatutorials.apache.kafka.audit;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 审计消息生成
 *
 * @author yangyunjiao
 */
@Slf4j
@Component
public class AuditMessageGenerator {
    AtomicInteger count = new AtomicInteger(1);


    @Scheduled(fixedDelay = 1500L)
    void info() {

        int index = count.getAndIncrement();

        AuditMessage message = new AuditMessage(
                "Audit [INFO] Event Message Generated",
                index,
                Instant.now());

        log.info(AuditMarker.getMarker(), message.toString());
    }

    @Scheduled(fixedDelay = 2500L)
    void debug() {

        int index = count.getAndIncrement();

        AuditMessage message = new AuditMessage(
                "Audit [DEBUG] Event Message Generated",
                index,
                Instant.now());

        log.debug(AuditMarker.getMarker(), message.toString());
    }

    @Scheduled(fixedDelay = 3500L)
    void error() {

        int index = count.getAndIncrement();

        AuditMessage message = new AuditMessage(
                "Audit [ERROR] Event Message Generated",
                index,
                Instant.now());

        log.error(AuditMarker.getMarker(), message.toString());
    }
}
